import xml.dom.minidom
import os
import OutPut_Py
protocolConstArray = []
protocolStructArray = []
protocolBodyArray = []
protocolFileArray = []
protocolNameArray = []
build_type = "python"
parentPath = os.path.abspath(os.path.dirname(os.getcwd()))
def readxml(xmlfilepath):
    global protocolConstArray
    global protocolStructArray
    global protocolBodyArray
    global protocolFileArray
    global protocolNameArray
    xmlfilepath = parentPath + "/protocol/fuck_protocol.xml"
    dom = xml.dom.minidom.parse(xmlfilepath)
    root = dom.documentElement
    consts = root.getElementsByTagName("enum")
    protocolStructArray = root.getElementsByTagName("struct")
    protocolBodyArray = root.getElementsByTagName("body")
    for commandData in consts:
        for child in commandData.getElementsByTagName("item"):
            protocolConstArray.append(child)

            if commandData.getAttribute("typedef") == "PROTOCOL_COMMAND_ID":
                protocolFileArray.append(child.getAttribute("name"))
                protocolNameArray.append(child)
    for bodyData in protocolBodyArray:
        protocolFileArray.append(bodyData.getAttribute("name"))

    protocolFileArray.append("Protocols")
    protocolFileArray.append("ProtocolConst")
    OutPut_Py.writeProtocol(protocolConstArray, protocolStructArray, protocolBodyArray, protocolFileArray, protocolNameArray)












